package com.jeesite.modules.rt.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.rt.entity.RtDeviceLine;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.rt.service.RtDeviceLineService;

/**
 * 网络信息Controller
 * @author 李寒冰
 * @version 2024-09-26
 */
@Controller
@RequestMapping(value = "${adminPath}/rt/rtDeviceLine")
public class RtDeviceLineController extends BaseController {

	@Autowired
	private RtDeviceLineService rtDeviceLineService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public RtDeviceLine get(String id, boolean isNewRecord) {
		return rtDeviceLineService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("rt:rtDevice:view")
	@RequestMapping(value = {"list", ""})
	public String list(RtDeviceLine rtDeviceLine, Model model) {
		model.addAttribute("rtDeviceLine", rtDeviceLine);
		return "modules/rt/rtDeviceLineList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("rt:rtDevice:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<RtDeviceLine> listData(RtDeviceLine rtDeviceLine, HttpServletRequest request, HttpServletResponse response) {
		rtDeviceLine.setPage(new Page<>(request, response));
		Page<RtDeviceLine> page = rtDeviceLineService.findPage(rtDeviceLine);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("rt:rtDevice:view")
	@RequestMapping(value = "form")
	public String form(RtDeviceLine rtDeviceLine, Model model) {
		RtDeviceLine deviceLineBySn = rtDeviceLineService.getDeviceLineBySn(rtDeviceLine.getSn());
		if(deviceLineBySn==null){
			deviceLineBySn = new RtDeviceLine();
			deviceLineBySn.setSn(rtDeviceLine.getSn());
		}
		model.addAttribute("rtDeviceLine", deviceLineBySn);
		return "modules/rt/rtDeviceLineForm";
	}


	/**
	 * 保存数据
	 */
	@RequiresPermissions("rt:rtDevice:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated RtDeviceLine rtDeviceLine) {
		rtDeviceLineService.save(rtDeviceLine);
		return renderResult(Global.TRUE, text("保存网络信息成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("rt:rtDevice:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(RtDeviceLine rtDeviceLine) {
		rtDeviceLineService.delete(rtDeviceLine);
		return renderResult(Global.TRUE, text("删除网络信息成功！"));
	}
	
}